
%global nodejs_pkg_major {{ NODE_PKG_MAJOR }}

%global nodejs_default_sitelib %{_prefix}/lib/node_modules
%global nodejs_private_sitelib %{nodejs_default_sitelib}_%{nodejs_pkg_major}

%bcond_without bundled_cjs_module_lexer
%bcond_without bundled_undici
%bcond_with bundled_zlib
%bcond_with bundled_openssl
%bcond_with bundled_libuv

%define _lto_cflags %{nil}

%global __python %{python3}

# openssl3 has marked openssl engine as deprecated
%bcond_without openssl_engine

# == Node.js Version ==
%global nodejs_major {{ NODE_MAJOR }}
%global nodejs_minor {{ NODE_MINOR }}
%global nodejs_patch {{ NODE_PATCH }}
%global baserelease 1
# nodejs_soversion - from NODE_MODULE_VERSION in src/node_version.h
%global nodejs_soversion {{ NODE_SOVERSION }}
%global nodejs_abi %{nodejs_soversion}
%global nodejs_version %{nodejs_major}.%{nodejs_minor}.%{nodejs_patch}
%global nodejs_release %{baserelease}
%global nodejs_envr %{nodejs_version}-%{nodejs_release}

%global nodejs_datadir %{_datarootdir}/node-%{nodejs_pkg_major}


# == Bundled Dependency Versions ==
# v8 - from deps/v8/include/v8-version.h
%global v8_major {{ V8_MAJOR }}
%global v8_minor {{ V8_MINOR }}
%global v8_build {{ V8_BUILD }}
%global v8_patch {{ V8_PATCH }}
%global v8_version %{v8_major}.%{v8_minor}.%{v8_build}.%{v8_patch}
%global v8_release %{nodejs_major}.%{nodejs_minor}.%{nodejs_patch}.%{nodejs_release}

# zlib - from deps/zlib/zlib.h
%global zlib_version {{ ZLIB_VERSION }}

# c-ares - from deps/cares/include/ares_version.h
# https://github.com/nodejs/node/pull/9332
%global c_ares_version {{ C_ARES_VERSION }}

# llhttp - from deps/llhttp/include/llhttp.h
%global llhttp_version {{ LLHTTP_VERSION }}

# libuv - from deps/uv/include/uv/version.h
%global libuv_version {{ LIBUV_VERSION }}

# nghttp2 - from deps/nghttp2/lib/includes/nghttp2/nghttp2ver.h
%global nghttp2_version {{ NGHTTP2_VERSION }}

# nghttp3 - from deps/ngtcp2/nghttp3/lib/includes/nghttp3/version.h
%global nghttp3_version {{NGHTTP3_VERSION}}

# ngtcp2 from deps/ngtcp2/ngtcp2/lib/includes/ngtcp2/version.h
%global ngtcp2_version {{NGTCP2_VERSION}}

# ICU - from tools/icu/current_ver.dep
%global icu_major {{ ICU_MAJOR }}
%global icu_minor {{ ICU_MINOR }}
%global icu_version %{icu_major}.%{icu_minor}

%global icudatadir %{nodejs_datadir}/icudata
%{!?little_endian: %global little_endian %(%{python3} -c "import sys;print (0 if sys.byteorder=='big' else 1)")}
# " this line just fixes syntax highlighting for vim that is confused by the above and continues literal

# simdutf from deps/simdutf/simdutf.h
%global simdutf_version {{SIMDUTF_VERSION}}

%global openssl30_minimum 3.0.2
%global punycode_version {{ PUNYCODE_VERSION }}

# npm - from deps/npm/package.json
%global npm_version {{ NPM_VERSION }}
%global npm_release %{nodejs_major}.%{nodejs_minor}.%{nodejs_patch}.%{nodejs_release}
%global npm_envr %{npm_version}-%{npm_release}

# uvwasi - from deps/uvwasi/include/uvwasi.h
%global uvwasi_version {{ UVWASI_VERSION }}

# histogram_c - assumed from timestamps
%global histogram_version 0.9.7



Name: nodejs
Version: %{nodejs_version}
Release: %{nodejs_release}
Summary: JavaScript runtime
License: Apache-2.0 AND Artistic-2.0 AND BSD-2-Clause AND BSD-3-Clause AND BlueOak-1.0.0 AND CC-BY-3.0 AND CC0-1.0 AND ISC AND MIT
Group: Development/Languages
URL: http://nodejs.org/

ExclusiveArch: %{nodejs_arches}

Source0: https://nodejs.org/dist/v%{nodejs_version}/node-v%{nodejs_version}.tar.gz
Source1: npmrc
Source2: btest402.js
# The binary data that icu-small can use to get icu-full capability
Source3: https://github.com/unicode-org/icu/releases/download/release-%{icu_major}-%{icu_minor}/icu4c-%{icu_major}_%{icu_minor}-data-bin-b.zip
Source4: https://github.com/unicode-org/icu/releases/download/release-%{icu_major}-%{icu_minor}/icu4c-%{icu_major}_%{icu_minor}-data-bin-l.zip
Source5: nodejs_abi.attr.in
Source6: nodejs_abi.req.in
Source200: nodejs-sources.sh
Source201: npmrc.builtin.in
Source202: nodejs.pc.in
Source203: v8.pc.in
Source300: test-runner.sh
Source301: test-should-pass.txt

{% for patch in PATCHES -%}
Patch: {{ patch }}
{% endfor -%}
{# #}

BuildRequires: make
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-jinja2
BuildRequires: brotli-devel
BuildRequires: gcc >= 8.3.0
BuildRequires: gcc-c++ >= 8.3.0
BuildRequires: pkgconf
BuildRequires: jq
BuildRequires: nodejs-packaging
BuildRequires: chrpath
BuildRequires: libatomic
BuildRequires: ninja-build
BuildRequires: unzip

%if %{without bundled_openssl}
BuildRequires: openssl >= %{openssl30_minimum}
BuildRequires: openssl-devel >= %{openssl30_minimum}
%endif

%if %{with bundled_zlib}
Provides: bundled(zlib) = %{zlib_version}
%else
BuildRequires: zlib-devel
%endif

%if %{with bundled_libuv}
Provides:      bundled(libuv) = %{libuv_version}
%else
BuildRequires: libuv-devel >= %{libuv_version}
Requires:      libuv >= %{libuv_version}
%endif

%if %{with bundled_cjs_module_lexer}
Provides: bundled(nodejs-cjs-module-lexer) = {{ LEXER_VERSION }}
%else
BuildRequires: nodejs-cjs-module-lexer
Requires: nodejs-cjs-module-lexer
%endif

%if %{with bundled_undici}
Provides: bundled(nodejs-undici) = {{ UNDICI_VERSION }}
%else
BuildRequires: nodejs-undici
Requires: nodejs-undici
%endif

Requires: ca-certificates
Requires: %{name}-libs = %{nodejs_envr}

Obsoletes: nodejs20 < 20.19.5

Recommends: %{name}-docs = %{nodejs_envr}
Recommends: %{name}-full-i18n = %{nodejs_envr}
Recommends: %{name}-npm >= %{npm_envr}

Provides: nodejs20 = %{nodejs_envr}
Provides: bundled(nghttp2) = %{nghttp2_version}
Provides: bundled(nghttp3) = %{nghttp3_version}
Provides: bundled(ngtcp2) = %{ngtcp2_version}
Provides: bundled(llhttp) = %{llhttp_version}
Provides: nodejs(abi) = %{nodejs_abi}
Provides: nodejs(abi%{nodejs_major}) = %{nodejs_abi}
Provides: nodejs(engine) = %{nodejs_version}
Provides: nodejs-punycode = %{punycode_version}
Provides: npm(punycode) = %{punycode_version}
Provides: bundled(c-ares) = %{c_ares_version}
Provides: bundled(v8) = %{v8_version}
Provides: bundled(icu) = %{icu_version}
Provides: bundled(uvwasi) = %{uvwasi_version}
Provides: bundled(histogram) = %{histogram_version}
Provides: bundled(simdutf) = %{simdutf_version}

{% if ADA_VERSION -%}
# Upstream has added a new URL parser that has no option to build as a shared
# library (19.7.0+)
Provides: bundled(ada) = {{ ADA_VERSION }}
{% endif %}



%description
Node.js is a platform built on Chrome's JavaScript runtime \
for easily building fast, scalable network applications. \
Node.js uses an event-driven, non-blocking I/O model that \
makes it lightweight and efficient, perfect for data-intensive \
real-time applications that run across distributed devices.}

%package devel
Summary: JavaScript runtime - development headers
Group: Development/Languages
Requires: %{name} = %{nodejs_envr}
Requires: %{name}-libs = %{nodejs_envr}
Requires: openssl-devel
%if !%{with bundled_zlib}
Requires: zlib-devel
%endif
Requires: brotli-devel
Requires: nodejs-packaging

%if %{without bundled_libuv}
Requires: libuv-devel
%endif

Provides: nodejs-devel = %{nodejs_envr}
Obsoletes: nodejs20-devel < 20.19.5

Provides: alternative-for(nodejs-devel) = %{nodejs_envr}
Conflicts: alternative-for(nodejs-devel)
Conflicts: nodejs-devel-pkg
# previously VP used for the same reason as alternative-for() above

%description devel
Development headers for the Node.js JavaScript runtime.


%package libs
Summary: Node.js and v8 libraries
Obsoletes: nodejs20-libs < 20.19.5

%description libs
Libraries to support Node.js and provide stable v8 interfaces.


%package full-i18n
Summary: Non-English locale data for Node.js
Requires: %{name} = %{nodejs_envr}
Obsoletes: nodejs20-full-i18n < 20.19.5

%description full-i18n
Optional data files to provide full-icu support for Node.js. Remove this
package to save space if non-English locales are not needed.


# ex. nodejs-v8-devel or nodejs22-v8-devel
%package v8-devel
Summary: v8 - development headers
Version: %{v8_version}
Release: %{v8_release}
Requires: %{name}-devel = %{nodejs_envr}
Requires: %{name}-libs = %{nodejs_envr}

%description v8-devel
Development headers for the v8 runtime.


%package -n npm
Summary: Node.js Package Manager
Version: %{npm_version}
Release: %{npm_release}
Recommends: %{name}-docs = %{nodejs_envr}
Obsoletes: nodejs20-npm <= 10.8.2 

%description -n npm
npm is a package manager for node.js. You can use it to install and publish
your node programs. It manages dependencies and does other cool stuff.


%package docs
Summary: Node.js API documentation
Group: Documentation
BuildArch: noarch
Requires(meta): %{name} = %{nodejs_envr}
Provides: nodejs-docs = %{nodejs_envr}
Obsoletes: nodejs20-docs < 20.19.5

%description -n %{name}-docs
The API documentation for the Node.js JavaScript runtime.



%prep
%autosetup -p1 -n node-v%{nodejs_version}
rm -rf deps/brotli
rm -rf deps/v8/third_party/jinja2
rm -rf tools/inspector_protocol/jinja2

%if %{without bundled_zlib}
rm -rf deps/zlib
%endif

%if %{without bundled_cjs_module_lexer}
rm -rf deps/cjs-module-lexer
%endif

%if %{without bundled_undici}
rm -rf deps/undici
%endif

%if %{without bundled_openssl}
rm -rf deps/openssl
%endif

# Replace any instances of unversioned python with python3
pfiles=( $(grep -rl python) )
%py3_shebang_fix ${pfiles[@]}



%build
# Decrease debuginfo verbosity to reduce memory consumption during final
# library linking
%global optflags %(echo %{optflags} | sed 's/-g /-g1 /')

export CC='%{__cc}'
export CXX='%{__cxx}'
export NODE_GYP_FORCE_PYTHON=%{python3}

extra_cflags=(
    -D_LARGEFILE_SOURCE
    -D_FILE_OFFSET_BITS=64
    -DZLIB_CONST
    -O3
    -fno-ipa-icf
)
export CFLAGS="%{optflags} ${extra_cflags[*]}" CXXFLAGS="%{optflags} ${extra_cflags[*]}"
export LDFLAGS="%{build_ldflags}"

# Fake up the unversioned python executable because gyp calls it from the PATH
mkdir .bin
cwd=$(pwd)
ln -srf /usr/bin/python3 ./.bin/python
export PATH="${cwd}/.bin:$PATH"

# lto options: --enable-lto
%{python3} configure.py \
          --verbose \
          --ninja \
          --prefix=%{_prefix} \
          --shared \
          --libdir=%{_lib} \
%if %{without openssl_engine}
          --without-openssl-engine \
%endif
          --shared-openssl \
          --openssl-conf-name=openssl_conf \
          --openssl-is-fips \
%if %{without bundled_zlib}
          --shared-zlib \
%endif
%if %{without bundled_cjs_module_lexer}
          --shared-builtin-cjs_module_lexer/lexer-path %{nodejs_private_sitelib}/cjs-module-lexer/lexer.js \
          --shared-builtin-cjs_module_lexer/dist/lexer-path %{nodejs_private_sitelib}/cjs-module-lexer/dist/lexer.js \
%endif
%if %{without bundled_undici}
          --shared-builtin-undici/undici-path %{nodejs_private_sitelib}/undici/loader.js \
%endif
          --shared-brotli \
%if %{without bundled_libuv}
          --shared-libuv \
%endif
          --with-intl=small-icu \
          --with-icu-default-data-dir=%{icudatadir} \
          --without-corepack \
          --openssl-use-def-ca-store \
          --use-prefix-to-find-headers

%ninja_build -C out/Release


%install

# The ninja build does not put the shared library in the expected location, so
# we will move it.
cp -f out/Release/lib/libnode.so.%{nodejs_soversion} out/Release/

%if 0%{?nodejs_major} >= 20
./tools/install.py install --dest-dir %{buildroot} --prefix %{_prefix}
%else
./tools/install.py install %{buildroot} %{_prefix}
%endif


# own the sitelib directory
mv %{buildroot}%{nodejs_default_sitelib} \
   %{buildroot}%{nodejs_private_sitelib}

rm -f %{buildroot}%{_datadir}/systemtap/tapset/node.stp


# Set the binary permissions properly
chmod 0755 %{buildroot}/%{_bindir}/node
chrpath --delete %{buildroot}%{_bindir}/node

# Rename the node binary
mv %{buildroot}%{_bindir}/node %{buildroot}%{_bindir}/node-%{nodejs_pkg_major}

# Adjust the npm binaries
# 1. Replace all hasbangs with versioned ones
readonly NPM_DIR="%{buildroot}%{nodejs_private_sitelib}/npm"
readonly SHEBANG_ERE='^#!/usr/bin/(env\s+)?node\b'
readonly SHEBANG_FIX='#!%{_bindir}/node-%{nodejs_pkg_major}'
readonly -a npm_bin_dirs=("${NPM_DIR}/bin" "${NPM_DIR}/node_modules")

find "${npm_bin_dirs[@]}" -type f \
| xargs grep --extended-regexp --files-with-matches "${SHEBANG_ERE}" \
| xargs sed --regexp-extended --in-place "s;${SHEBANG_ERE};${SHEBANG_FIX};"

# 2. Replace original links with the adjusted ones
for bin in npm npx; do
  ln -srf "%{buildroot}%{nodejs_private_sitelib}/npm/bin/${bin}-cli.js" \
          "%{buildroot}%{_bindir}/${bin}-%{nodejs_pkg_major}"
  rm -f   "%{buildroot}%{_bindir}/${bin}"
done

# 3. Add the symlinks back for the default version
ln -srf %{buildroot}%{_bindir}/node-%{nodejs_pkg_major} \
        %{buildroot}%{_bindir}/node

ln -srf %{buildroot}%{_bindir}/npm-%{nodejs_pkg_major} \
        %{buildroot}%{_bindir}/npm

ln -srf %{buildroot}%{_bindir}/npx-%{nodejs_pkg_major} \
        %{buildroot}%{_bindir}/npx

# Fix shell scripts that call 'node' as command
readonly -a known_shell_scripts=(
    "${NPM_DIR}/bin/node-gyp-bin/node-gyp"
    "${NPM_DIR}/node_modules/@npmcli/run-script/lib/node-gyp-bin/node-gyp"
)
sed --regexp-extended --in-place 's;\bnode(\s);%{_bindir}/node-%{nodejs_pkg_major}\1;' "${known_shell_scripts[@]}"

# Install library symlink
ln -srf %{buildroot}%{_libdir}/libnode.so.%{nodejs_soversion} \
        %{buildroot}%{_libdir}/libnode.so

# Install v8 compatibility symlinks
for header in %{buildroot}%{_includedir}/node/libplatform %{buildroot}%{_includedir}/node/v8*.h; do
    header=$(basename ${header})
    ln -sf ./node/${header} %{buildroot}%{_includedir}/${header}
done
ln -s ./node/cppgc %{buildroot}%{_includedir}/cppgc

for soname in libv8 libv8_libbase libv8_libplatform; do
  ln -srf %{buildroot}%{_libdir}/libnode.so.%{nodejs_soversion} %{buildroot}%{_libdir}/${soname}.so.%{v8_major}.%{v8_minor}
  ln -srf %{buildroot}%{_libdir}/libnode.so.%{nodejs_soversion} %{buildroot}%{_libdir}/${soname}.so
  ln -srf %{buildroot}%{_libdir}/libnode.so.%{nodejs_soversion} %{buildroot}%{_libdir}/${soname}.so.%{v8_major}
done

# Create automatic RPM requires generator for this stream
mkdir -p "${RPM_BUILD_ROOT}%{_rpmconfigdir}/fileattrs"
sed -e 's;@NODEJS_VERSION_MAJOR@;%{nodejs_pkg_major};g' \
    <%{SOURCE5} >"${RPM_BUILD_ROOT}%{_rpmconfigdir}/fileattrs/nodejs%{nodejs_pkg_major}_abi.attr"
sed -e 's;@NODEJS_VERSION_MAJOR@;%{nodejs_pkg_major};g' \
    <%{SOURCE6} >"${RPM_BUILD_ROOT}%{_rpmconfigdir}/nodejs%{nodejs_pkg_major}_abi.req"

# install documentation
mkdir -p %{buildroot}%{_pkgdocdir}/html
cp -pr doc/* %{buildroot}%{_pkgdocdir}/html
rm -f %{buildroot}%{_pkgdocdir}/html/nodejs.1

# node-gyp needs common.gypi too
mkdir -p %{buildroot}%{nodejs_datadir}
cp -p common.gypi %{buildroot}%{nodejs_datadir}

# The config.gypi file is platform-dependent, so rename it to not conflict
mv %{buildroot}%{_includedir}/node/config.gypi \
   %{buildroot}%{_includedir}/node/config-%{_arch}.gypi

# Install the GDB init tool into the documentation directory
mv %{buildroot}/%{_datadir}/doc/node/gdbinit %{buildroot}/%{_pkgdocdir}/gdbinit

mkdir -p %{buildroot}%{_mandir}/nodejs-%{nodejs_pkg_major}/man1 \
         %{buildroot}%{_mandir}/nodejs-%{nodejs_pkg_major}/man5 \
         %{buildroot}%{_mandir}/nodejs-%{nodejs_pkg_major}/man7 \
         %{buildroot}%{nodejs_default_sitelib} \
         %{buildroot}%{nodejs_private_sitelib}/npm/man \
         %{buildroot}%{_pkgdocdir}/npm

# install manpage docs to mandir
cp -pr deps/npm/man/* \
       %{buildroot}%{_mandir}/nodejs-%{nodejs_pkg_major}/
rm -rf %{buildroot}%{nodejs_private_sitelib}/npm/man
ln -srf %{buildroot}%{_mandir}/nodejs-%{nodejs_pkg_major} \
        %{buildroot}%{nodejs_private_sitelib}/npm/man

for i in 1 5 7; do
  mkdir -p %{buildroot}%{_mandir}/man${i}
  for manpage in %{buildroot}%{nodejs_private_sitelib}/npm/man/man$i/*; do
    basename=$(basename ${manpage})
    ln -srf %{buildroot}%{nodejs_private_sitelib}/npm/man/man${i}/${basename} \
            %{buildroot}%{_mandir}/man${i}/${basename}
  done
done

# Install the node interpreter manpage
mv %{buildroot}%{_mandir}/man1/node.1 \
   %{buildroot}%{_mandir}/nodejs-%{nodejs_pkg_major}/man1/

ln -srf %{buildroot}%{_mandir}/nodejs-%{nodejs_pkg_major}/man1/node.1 \
        %{buildroot}%{_mandir}/man1/

# Install Gatsby HTML documentation to %%{_pkgdocdir}
cp -pr deps/npm/docs %{buildroot}%{_pkgdocdir}/npm/
rm -rf %{buildroot}%{nodejs_private_sitelib}/npm/docs
ln -srf %{buildroot}%{_pkgdocdir}/npm %{buildroot}%{nodejs_private_sitelib}/npm/docs

# Node tries to install some python files into a documentation directory
# (and not the proper one). Remove them for now until we figure out what to
# do with them.
rm -f %{buildroot}/%{_defaultdocdir}/node/lldb_commands.py \
      %{buildroot}/%{_defaultdocdir}/node/lldbinit

# Some NPM bundled deps are executable but should not be. This causes
# unnecessary automatic dependencies to be added. Make them not executable.
# Skip the npm bin directory or the npm binary will not work.
find %{buildroot}%{nodejs_private_sitelib}/npm \
    -not -path "%{buildroot}%{nodejs_private_sitelib}/npm/bin/*" \
    -executable -type f \
    -exec chmod -x {} \;

# The above command is a little overzealous. Add a few permissions back.
chmod 0755 %{buildroot}%{nodejs_private_sitelib}/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin/node-gyp
chmod 0755 %{buildroot}%{nodejs_private_sitelib}/npm/node_modules/node-gyp/bin/node-gyp.js

# Drop the NPM builtin configuration in place
sed -e 's#@SYSCONFDIR@#%{_sysconfdir}#g' \
    %{SOURCE201} > %{buildroot}%{nodejs_private_sitelib}/npm/npmrc

# Drop the NPM default configuration in place
mkdir -p %{buildroot}%{_sysconfdir}
cp %{SOURCE1} %{buildroot}%{_sysconfdir}/npmrc

# Install the full-icu data files
mkdir -p %{buildroot}%{icudatadir}
%if 0%{?little_endian}
unzip -d %{buildroot}%{icudatadir} %{SOURCE4} icudt%{icu_major}l.dat
%else
unzip -d %{buildroot}%{icudatadir} %{SOURCE3} icudt%{icu_major}b.dat
%endif

# Add pkg-config files
mkdir -p %{buildroot}%{_libdir}/pkgconfig
sed -e 's#@PREFIX@#%{_prefix}#g' \
    -e 's#@INCLUDEDIR@#%{_includedir}#g' \
    -e 's#@LIBDIR@#%{_libdir}#g' \
    -e 's#@PKGCONFNAME@#nodejs-%{nodejs_pkg_major}#g' \
    -e 's#@NODEJS_VERSION@#%{nodejs_version}#g' \
    %{SOURCE202} > %{buildroot}%{_libdir}/pkgconfig/nodejs-%{nodejs_pkg_major}.pc

sed -e 's#@PREFIX@#%{_prefix}#g' \
    -e 's#@INCLUDEDIR@#%{_includedir}#g' \
    -e 's#@LIBDIR@#%{_libdir}#g' \
    -e 's#@PKGCONFVERSION@#v8-%{v8_major}.%{v8_minor}#g' \
    -e 's#@V8_VERSION@#%{v8_version}#g' \
    %{SOURCE203} > %{buildroot}%{_libdir}/pkgconfig/v8-%{v8_major}.%{v8_minor}.pc


%check
#run unit test that should pass from list
LD_LIBRARY_PATH=%{buildroot}%{_libdir} \
  bash %{SOURCE300} \
       %{buildroot}/%{_bindir}/node-%{nodejs_pkg_major} \
       %{_builddir}/node-v%{nodejs_version}/test/ \
       %{SOURCE301}

# Fail the build if the versions don't match
LD_LIBRARY_PATH=%{buildroot}%{_libdir} %{buildroot}/%{_bindir}/node-%{nodejs_pkg_major} -e "require('assert').equal(process.versions.node, '%{nodejs_version}')"
LD_LIBRARY_PATH=%{buildroot}%{_libdir} %{buildroot}/%{_bindir}/node-%{nodejs_pkg_major} -e "require('assert').equal(process.versions.v8.replace(/-node\.\d+$/, ''), '%{v8_version}')"
LD_LIBRARY_PATH=%{buildroot}%{_libdir} %{buildroot}/%{_bindir}/node-%{nodejs_pkg_major} -e "require('assert').equal(process.versions.ares.replace(/-DEV$/, ''), '%{c_ares_version}')"

# Ensure we have punycode and that the version matches
LD_LIBRARY_PATH=%{buildroot}%{_libdir} %{buildroot}/%{_bindir}/node-%{nodejs_pkg_major} -e "require(\"assert\").equal(require(\"punycode\").version, '%{punycode_version}')"

# Ensure we have npm and that the version matches
LD_LIBRARY_PATH=%{buildroot}%{_libdir} %{buildroot}%{_bindir}/node-%{nodejs_pkg_major} %{buildroot}%{_bindir}/npm-%{nodejs_pkg_major} version --json |jq -e '.npm == "%{npm_version}"'

# Make sure i18n support is working
NODE_PATH=%{buildroot}%{_prefix}/lib/node_modules:%{buildroot}%{nodejs_private_sitelib}/npm/node_modules LD_LIBRARY_PATH=%{buildroot}%{_libdir} %{buildroot}/%{_bindir}/node-%{nodejs_pkg_major} --icu-data-dir=%{buildroot}%{icudatadir} %{SOURCE2}

%pretrans -p <lua>
path = "/usr/lib/node_modules"
st = posix.stat(path)
if st and st.type == "link" then
  os.remove(path)
end



%files
%doc CHANGELOG.md onboarding.md GOVERNANCE.md README.md
%{_bindir}/node
%{_bindir}/node-%{nodejs_pkg_major}
%doc %{_mandir}/man1/node.1*
%{nodejs_default_sitelib}

{% if NODE_MAJOR < 19 -%}
%dir %{_datadir}/systemtap
%dir %{_datadir}/systemtap/tapset
%{_datadir}/systemtap/tapset/node.stp
%dir %{_usr}/lib/dtrace
%{_usr}/lib/dtrace/node.d
{% endif %}

%dir %{nodejs_private_sitelib}
%doc %{_mandir}/nodejs-%{nodejs_pkg_major}/man1/node.1*


%files devel
%{_includedir}/node
%{_libdir}/libnode.so
%{nodejs_datadir}/common.gypi
%{_pkgdocdir}/gdbinit
%{_libdir}/pkgconfig/nodejs-%{nodejs_pkg_major}.pc
%{_rpmconfigdir}/fileattrs/nodejs%{nodejs_pkg_major}_abi.attr
%{_rpmconfigdir}/nodejs%{nodejs_pkg_major}_abi.req


%files full-i18n
%dir %{icudatadir}
%{icudatadir}/icudt%{icu_major}*.dat


%files libs
%license LICENSE
%{_libdir}/libnode.so.%{nodejs_soversion}
%{_libdir}/libv8.so.%{v8_major}.%{v8_minor}
%{_libdir}/libv8_libbase.so.%{v8_major}.%{v8_minor}
%{_libdir}/libv8_libplatform.so.%{v8_major}.%{v8_minor}
%dir %{nodejs_datadir}/
%{_libdir}/libv8.so.%{v8_major}
%{_libdir}/libv8_libbase.so.%{v8_major}
%{_libdir}/libv8_libplatform.so.%{v8_major}


%files v8-devel
%{_includedir}/libplatform
%{_includedir}/v8*.h
%{_includedir}/cppgc
%{_libdir}/libv8.so
%{_libdir}/libv8_libbase.so
%{_libdir}/libv8_libplatform.so
%{_libdir}/pkgconfig/v8-%{v8_major}.%{v8_minor}.pc


%files -n npm
%{_bindir}/npm
%{_bindir}/npx
%config(noreplace) %{_sysconfdir}/npmrc
%ghost %{_sysconfdir}/npmignore

%doc %{_mandir}/man*/
%exclude %doc %{_mandir}/man1/node.1*

%{_bindir}/npm-%{nodejs_pkg_major}
%{_bindir}/npx-%{nodejs_pkg_major}
%{nodejs_private_sitelib}/npm

%doc %{_mandir}/nodejs-%{nodejs_pkg_major}/
%exclude %doc %{_mandir}/nodejs-%{nodejs_pkg_major}/man1/node.1*


%files docs
%doc doc
%dir %{_pkgdocdir}
%{_pkgdocdir}/html
%{_pkgdocdir}/npm/docs



%changelog
* Wed Sep 17 2025 jeremiazhao <jeremiazhao@tencent.com> - 20.19.5-1
- upgraded to upstream 20.19.5
